home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / misc / samples2 / popupmnu.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-24  |  4.0 KB  |  116 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5820
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1770
  7.    ClientWidth     =   7365
  8.    Height          =   6510
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5820
  12.    ScaleWidth      =   7365
  13.    Top             =   1140
  14.    Width           =   7485
  15.    Begin CommandButton Command1 
  16.       Caption         =   "Create Menu Item"
  17.       Height          =   495
  18.       Left            =   3075
  19.       TabIndex        =   0
  20.       Top             =   2670
  21.       Width           =   1815
  22.    End
  23.    Begin Menu mnuExit 
  24.       Caption         =   "Exit"
  25.    End
  26. Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
  27. Declare Function GetMenu Lib "User" (ByVal hWnd As Integer) As Integer
  28. Declare Function InsertMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  29. Declare Sub DrawMenuBar Lib "User" (ByVal hWnd As Integer)
  30. Declare Function CreatePopupMenu Lib "User" () As Integer
  31. Declare Function AppendMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  32. Const MF_BYCOMMAND = &H0
  33. Const MF_BYPOSITION = &H400
  34. Const MF_INSERT = &H0
  35. Const MF_POPUP = &H10
  36. Const MF_STRING = &H0
  37. Const MF_ENABLED = &H0
  38. Const WM_COMMAND = &H111
  39. Const WM_MENUSELECT = &H11F
  40. Dim wParam As Integer
  41. Sub Command1_Click ()
  42.     'Get Notepad's window handle
  43.     Handle% = FindWindow("notepad", 0&)
  44.     'Determine if Notepad is running or not
  45.     If Handle% = 0 Then
  46.         Msg$ = "Notepad is not running.  Should I start it?"
  47.         'Prompt to start Notepad
  48.         Ans% = MsgBox(Msg$, 36)
  49.         If Ans% = 6 Then
  50.             'Start Notepad
  51.             X% = Shell("notepad")
  52.             If X% Then
  53.                 'Now get its handle again
  54.                 Handle% = FindWindow("notepad", 0&)
  55.             Else
  56.                 'Something's wrong with Notepad
  57.                 Msg$ = "Can't start Notepad."
  58.                 MsgBox Msg$
  59.                 Exit Sub
  60.             End If
  61.         Else
  62.             Exit Sub
  63.         End If
  64.     End If
  65.     'Get the menu handle for Notepad
  66.     hMenu% = GetMenu(Handle%)
  67.     'Create a popup menu
  68.     hMenuPopup% = CreatePopupMenu()
  69.     X% = AppendMenu(hMenuPopup%, MF_ENABLED Or MF_STRING, 50, "Item &1")
  70.     X% = AppendMenu(hMenuPopup%, MF_ENABLED Or MF_STRING, 51, "Item &2")
  71.     X% = AppendMenu(hMenuPopup%, MF_ENABLED Or MF_STRING, 52, "Item &3")
  72.     X% = AppendMenu(hMenuPopup%, MF_ENABLED Or MF_STRING, 53, "Item &4")
  73.     'Add a top level menu item to Notepad's menu
  74.     Success% = AppendMenu(hMenu%, MF_STRING Or MF_POPUP, hMenuPopup%, "&Programs") 'Adds menu
  75.      'Redraw the menu
  76.     DrawMenuBar (Handle%)
  77. End Sub
  78. Sub Form_Unload (Cancel As Integer)
  79.     End
  80. End Sub
  81. Sub mnuExit_Click ()
  82.     Unload Me
  83. End Sub
  84. Sub MsgBlaster1_Message (MsgVal As Integer, wParam As Integer, lParam As Long, ReturnVal As Long)
  85.     If MsgVal = WM_MENUSELECT Then
  86.         Select Case wParam
  87.         Case 0
  88.             MsgBox "Item 1 was selected"
  89.         Case 1
  90.             MsgBox "Item 2 was selected"
  91.         Case 2
  92.             MsgBox "Item 3 was selected"
  93.         Case 3
  94.             MsgBox "Item 4 was selected"
  95.         End Select
  96.     End If
  97. End Sub
  98. Sub SubClass1_AfterDefProcess (wnd As Integer, Msg As Integer)
  99.     Select Case wParam
  100.     Case 0
  101.         MsgBox "Item 1 was selected"
  102.     Case 1
  103.         MsgBox "Item 1 was selected"
  104.     Case 2
  105.         MsgBox "Item 1 was selected"
  106.     Case 3
  107.         MsgBox "Item 1 was selected"
  108.     End Select
  109. End Sub
  110. Sub SubClass1_MsgQueue (wnd As Integer, Msg As Integer, wp As Integer, lp As Long, retval As Long, dodef As Integer)
  111.     If Msg = WM_MENUSELECT Then
  112.         wParam = wp
  113.         dodef = True
  114.     End If
  115. End Sub
  116.